The present invention relates to concurrency control for updating databases and, in particular, to selective application of a pessimistic concurrency control when updating databases.
In database systems a transaction is a mechanism that allows multiple users to atomically perform in isolation database modifications that are guaranteed to be consistent and resilient when committed. With reference to database information in the form of software objects, for example, a write/write conflict occurs when an object modified in one transaction (e.g., by one user or process) is modified by another concurrent transaction (e.g., by another user or process). For example, when a transaction (e.g., by a first user) writes an object and executes complex behavior based upon the state of that object, the transaction cannot commit successfully if in the meantime another transaction (e.g., by a second user) has committed a modification of that object.
One way to prevent such concurrency conflicts is to incorporate into the database system a pessimistic concurrency control with which the database can be locked to prevent it from being accessed by more than one user or process at a time. With conventional pessimistic concurrency controls, every transaction locks the database objects being modified to prevent conflicts with other transactions. However, locking can be computationally expensive because it requires arbitration by a lock manager and deadlock detection. Locking objects also enforces an ordering of all transactions so that the database remains in a consistent state, but this comes at the cost of decreased availability of the locked objects. When a transaction locks an object, other transactions are restricted from accessing the object until the transaction releases its lock.
Another way to prevent concurrency conflicts is to incorporate into the database system an optimistic concurrency control that uses application code to avoid the conflicts in accessing a database. Logical conflict detection is used to detect conflicts and interrupt conflicting transactions, and a replay mechanism attempts to complete or commit the interrupted transaction within a predetermined number of replays or xe2x80x9credos.xe2x80x9d Failure to complete the interrupted transaction within the predetermined number of replays results in a transaction failure (retryFailure). However, optimistic concurrency controls are susceptible to livelock and process starvation wherein a transaction is prevented from committing because successive other transactions are committed first.
The present invention includes software and a method for concurrently updating a database. For example, the method includes determining whether a database update conflicts with another database update, applying an optimistic concurrency control for each database update that does not conflict with another database update, and applying a pessimistic concurrency control for each database update that does conflict with another database update. This invention provides a selective locking concurrency control that selectively applies transaction serialization and locking only when transaction conflicts are detected. As a result, the selective locking concurrency control avoids livelock transaction failures and provides deterministic transaction completion without the computational expense of a conventional pessimistic concurrency control.
Additional advantages of the present invention will be apparent from the detailed description of the preferred embodiment thereof, which proceeds with reference to the accompanying drawings.